﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using Common;
using WebComputers.Class;

namespace WebComputers
{
    public partial class ChiTietSanPham : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FillData();
            }
        }

        private void FillData()
        {
            try
            {
                if (Request.QueryString.Count > 0)
                {
                    if (DAHelper.CheckNumber(Request.QueryString["id"]))
                    {
                        int id = Convert.ToInt32(Request.QueryString["id"]);
                        var dmhh = DanhMucHangHoaDAO.SelectByIdLinq(id);
                        if (dmhh != null)
                        {
                            lblDonGia.Text = string.Format("{0:#,##}", dmhh.dGiaBan);
                            lblMaSanPham.Text = dmhh.sMaHangHoa;
                            lblTenSanPham.Text = dmhh.sTenHangHoa;
                            lblTinhTrang.Text = "Có hàng";
                            imgHinhDaiDien.ImageUrl = DAHelper.FillImage(dmhh.sHinhDaiDien);
                            litMoTa.Text = dmhh.sMoTa;
                        }                        
                    }

                    if (string.IsNullOrEmpty(lblTenSanPham.Text))
                    {
                        Response.Redirect("SanPham.aspx", false);
                    }
                }
                else
                {
                    Response.Redirect("SanPham.aspx", false);
                }
            
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            
        }
    }
}